package com.dao.impl;

import java.util.List;

import com.wecollege.domain.User;

public class MemberDao extends HibernateDaoSupport implements IMemberDao{
	
	public User get(Integer id){
		return getHibernateTemplate().get(Member.class, id);
	}
	
	public Member get(String openId){
		if(openId == null)
			return null;
		return (Member) (this.getHibernateTemplate().find("from Member m where m.openId=?", openId).size()>0 ? this.getHibernateTemplate().find("from Member m where u.openId=?", openId).get(0) : null);
	}
	
	public Integer save(Member member){
		return (Integer)getHibernateTemplate()
			.save(member);
	}
	
	public void update(Member member){
		getHibernateTemplate().update(member);
	}
	
	public void delete(Member member){
		getHibernateTemplate().delete(member);
	}
	
	public void delete(Integer id){
		getHibernateTemplate().delete(get(id));
	}
	
	public void delete(String openId){
		getHibernateTemplate().delete(get(openId));
	}
	
	public List<Member> findAll(){
		return (List<Member>)getHibernateTemplate()
				.find("from Member");
	}
}
